Skip to content

[Feature] Forked Mainnet Simulation Tests#191

Merged
jribbink merged 91 commits intomainfrom
feature/forked-simulations
Apr 3, 2026
Merged

[Feature] Forked Mainnet Simulation Tests#191
jribbink merged 91 commits intomainfrom
feature/forked-simulations

Conversation

@jribbink
Copy link
Copy Markdown
Contributor

@jribbink jribbink commented Feb 27, 2026

Description

Feature branch that adds forked rebalance simulations for the real PYUSD0 strategy, mirroring those initially created via mocked bootstrapped tests.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

RZhang05 and others added 30 commits January 8, 2026 16:21
EVM.store(target: poolAddr, slot: slotHex(3), value: zero32)

// --- Slot 4: liquidity = uint128 max ---
let liquidityAmount: UInt256 = 340282366920938463463374607431768211455 // 2^128 - 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that we are mocking the uniswap pool in a way that have max liquidity. I understand this is useful to ensure that no matter how much token to swap, the swapped price can always be the targeted price we set.

But in real world, the liquidity is often capped, and we also want to verify the behavior when there isn't enough liquidity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is a fair concern.

The intitial scope of the forked simulations was to replicate the existing rebalance style tests, as the team wasn't completely that the behaviour would be matched in a real integration-style test against real oracle integrations & EVM pools.

That being said, I agree that the rigidity leaves room for error. Could be worth exploring another style test as a follow-up with more realistic liquidity ticks, but only asserting properties instead of absolute values (e.g. rebalance happens, health factor improves/hits target, realsistic slippage values don't affect system negatively) rather than exact values. Open to ideas on what that should look like.

@@ -0,0 +1,294 @@
#test_fork(network: "mainnet-fork", height: 143292255)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference in the setup between this forked mainnet and rebalance_scenario1_test.cdc?

What is covered in this tests but is not covered in there?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference is just using the contracts deployed on mainnet instead of the mocked ones (e.g. MockSwapper, MockOracle) in the original rebalance_scenario*.cdc. Otherwise, the tests are identical by design and the expected values are exactly the same.

Copy link
Copy Markdown
Contributor Author

@jribbink jribbink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM - Can you approve the PR again @zhangchiqing (It doesn't let me because I opened it)

@jribbink jribbink merged commit 5e77b29 into main Apr 3, 2026
15 checks passed
@jribbink jribbink deleted the feature/forked-simulations branch April 3, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants